package com.creative.accountsdk.net.account;

import android.util.Log;

import com.creative.accountsdk.UmsChannel;
import com.creative.accountsdk.UserData;
import com.creative.accountsdk.bean.CourseInfo;
import com.creative.accountsdk.net.Protocol;
import com.creative.accountsdk.net.XParams;
import com.loopj.android.http.RequestParams;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 教师 -  课程列表 （选择任教）
 *
 *
 * @author  David
 * @version 1.0
 * @created 2015-11-25
 */
public class CourseListProtocol extends Protocol {

    public JSONObject      returnMap;

    public List<CourseInfo> courseList;
    UserData  userData;
    public CourseListProtocol(){
        userData = UserData.getInstance();
    }
    @Override
    public RequestParams getParams() {
        return new XParams()
                .put("uid", userData.getUid())
                .put(UmsChannel.PARAM_NAME, UmsChannel.getChannel())
                .getParams();
    }

    @Override
    public String getUrl() {
        return getUrlPrefix()+"courses/";
    }

    @Override
    protected void parseReturnMap(JSONObject returnMap) {
        this.returnMap = returnMap;
            Log.e("Tag", "返回课程列表信息.." + returnMap.toString());
            try{
                //教师  课程列表 信息
                if(returnMap.has("courses")){
                    JSONArray  othercla = returnMap.optJSONArray("courses");
                    if(null!=othercla){
                        courseList = new ArrayList<>();
                        CourseInfo infor =  new CourseInfo();
                        for(int i=0;i<othercla.length();i++){
                            infor =  ((CourseInfo)infor.clone()).setJsonTovo(((JSONObject) othercla.get(i)));
                            courseList.add(infor);
                        }
                    }
                }
            }catch (Exception e){
                e.printStackTrace();
            }
    }

}
